package com.lt.contract.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.lt.contract.bean.NM_CONTRACT_2019;
import com.lt.contract.entity.NmMongoliaCircuitSharing;
import com.lt.contract.service.NmMongoliaCircuitSharingService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 国内电路分摊收入(NmMongoliaCircuitSharing)表控制层
 *
 * @author makejava
 * @since 2020-02-15 21:44:55
 */
@RestController
@RequestMapping("/nmMongoliaCircuitSharing")
public class NmMongoliaCircuitSharingController {
    /**
     * 服务对象
     */
    @Resource
    private NmMongoliaCircuitSharingService nmMongoliaCircuitSharingService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
//    @GetMapping("selectOne")
//    public NmMongoliaCircuitSharing selectOne(id) {
//        return this.nmMongoliaCircuitSharingService.queryById(id);
//    }

    /**
     * 获取  国内电路分摊收入列表
     * @param params
     * @return
     */
    @CrossOrigin
    @ResponseBody
    @GetMapping("/queryAll")
    public JSONArray queryAll(@RequestParam String params){
        System.out.println(params);
        List<NmMongoliaCircuitSharing> contractList = null;
        try {
            Map<String,Object> map = JSON.parseObject(params);
            contractList = nmMongoliaCircuitSharingService.queryAll(map);
            JSONArray result = JSON.parseArray(JSON.toJSONString(contractList));
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

    /**
     * 获取  国内电路分摊收入总数
     * @param params
     * @return
     */
    @CrossOrigin
    @ResponseBody
    @GetMapping("/queryAllCount")
    public Long queryAllCount(@RequestParam String params){
        try {
            Map<String,Object> map = JSON.parseObject(params);
            Long count = nmMongoliaCircuitSharingService.queryAllCount(map);
            return count;
        }catch (Exception e){
            e.printStackTrace();
            return 0L;
        }

    }





}
